package com.situ.day5;

public class Student extends Object{
    //属性私有
    private int id;
    private String name;
    private int age;
    private String gender;

    //构造方法：没有返回值，方法名和类名一样
    //Student student = new Student(); new对象时候调用的方法
    //无参构造方法
    //不写任何构造方法，系统默认提供一个无参构造方法，如果你写了任何构造方法，
    //系统就不再提供任何构造方法
    public Student() {
        System.out.println("Student.Student");
    }

    //有参构造方法
    public Student(int id, String name, int age, String gender) {
        this.id = id;
        this.name = name;
        this.age = age;
        this.gender = gender;
    }

    //Variable 'id' is assigned to itself
    //就近原则
    public void setId(int id) {
        this.id = id;
        //this代表当前类这个对象
        //student.setId(1);
    }

    public int getId() {
        return id;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        if (age >= 1 && age <= 125) {
            this.age = age;
        }
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    //重写、覆盖
    @Override
    public String toString() {
        return "Student{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", age=" + age +
                ", gender='" + gender + '\'' +
                '}';
    }
}
